package com.bzy.blp.upms.web.controller;

import com.bzy.blp.upms.service.MenuService;
import com.bzy.blp.upms.vo.MainmenuVO;
import com.bzy.common.bean.Result;
import com.bzy.common.validator.Validator;
import com.bzy.common.validator.annotation.ValidateParam;
import com.bzy.shiro.util.SessionUtil;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/menu")
public class MenuController {

    @Autowired
    MenuService menuService;

    /**
     * 获取资源菜单
     * @param request
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/getMenuList")
    public Result getMenuList(
            @ApiParam(value = "appKey", required = true) @ValidateParam({Validator.NOT_BLANK}) String appKey
            , HttpServletRequest request) throws Exception {
        Result result = new Result();
        String userName = (String) SessionUtil.getPrincipal();
        List<MainmenuVO> mainmenuVO = menuService.queryMenu(userName, appKey);
        result.setData(mainmenuVO);
        return result;
    }

    /**
     * 根据 resourceId 获取子菜单
     * @param resourceId
     * @param request
     * @return
     * @throws Exception
     */
    @GetMapping(value = "/getMenuChildrenList")
    public Result getMenuChildrenList(
            @ApiParam(value = "资源 resourceId", required = true) @ValidateParam({Validator.NOT_BLANK}) String resourceId,
            @ApiParam(value = "appKey", required = true) @ValidateParam({Validator.NOT_BLANK}) String appKey,
            HttpServletRequest request) throws Exception {
        Result result = new Result();
        String userName = (String) SessionUtil.getPrincipal();
        List<MainmenuVO> mainmenuVOS = menuService.queryMenuNewChlid(userName, appKey, resourceId);
        result.setData(mainmenuVOS);
        return result;
    }

}
